import {create} from "zustand";
import {FileObj} from "@/api/web/FileApi.ts";

export interface FileViewStore {
    previewFile: FileObj | null
    setPreviewFile: (previewFile: FileObj) => void
    previewDrawerOpen: boolean
    setPreviewDrawerOpen: (previewDrawerOpen: boolean) => void
}

export const useFileViewStore = create<FileViewStore>((set) => {
    return {
        previewFile: null,
        setPreviewFile: (previewFile) => {
            set({previewFile})
        },
        previewDrawerOpen: false,
        setPreviewDrawerOpen: (previewDrawerOpen) => {
            set({previewDrawerOpen})
        },
    }
})

////////////////////////////////////////////////

export interface FileDiveStore {
    // 文件夹内容
    content: FileObj[]
    // 是否正在加载
    loading: boolean
    // 当前页码
    pageCurrent: number
    // 分页大小
    pageSize: number
    // 总数
    total: number
    setPageSize: (pageSize: number) => void
    setPageCurrent: (pageCurrent: number) => void
    setContent: (content: FileObj[]) => void
    setTotal: (total: number) => void
    setLoading: (loading: boolean) => void
}

export const useFileDiveStore = create<FileDiveStore>((set) => {
    class FDS implements FileDiveStore {
        content = []
        loading = false
        pageCurrent = 1
        pageSize = 50
        total = 0
        setPageSize = (pageSize: number) => {
            set({pageSize})
        }
        setPageCurrent = (pageCurrent: number) => {
            set({pageCurrent})
        }
        setContent = (content: FileObj[]) => {
            set({content})
        }
        setTotal = (total: number) => {
            set({total})
        }
        setLoading = (loading: boolean) => {
            set({loading})
        }
    }

    return new FDS()
})